/**
 * @param {number[]} nums
 * @return {number[]}
 */
 var sortArrayByParityII = function(nums) {
  let index1 = 0
  let index2 = 1
  let result = []
  for(const num of nums){
    if(num%2==0){
      result[index1] = num
      index1+=2
    }else {
      result[index2] = num
      index2+=2
    }
  }
  return result
};